<?php defined('SYSPATH') or die('No direct script access.');

class Common_Controller extends Controller 
{
	function setlang($lang)
    {
	    // Array of allowed languages
	    $locales = Config::item('locale.allowed_locales');
		
        // Store locale config values
	    Config::set('locale.lang', $lang);
	    Config::set('locale.language', $locales[$lang]);
	
	    // Overwrite setlocale which has already been set before in Kohana::setup()
	    setlocale(LC_ALL, Config::item('locale.language').'.UTF-8');
	
	    // Finally set a language cookie for 6 months
	    cookie::set('lang', $lang, 15768000);
		
		url::redirect($_SERVER['HTTP_REFERER']);
    }
}
